package com.example.template.core.utils;

import javax.validation.constraints.NotNull;

/**
 * @ClassName GeneCodeUtil
 * @Description TODO 通用编码生成工具
 * @Date 2019/3/28 21:14
 **/
public class GenerateCodeUtil {

    public static String generateCode(@NotNull String preString, @NotNull String mindString, int generateLength, String way) {
        return generateCode(preString, mindString, "", generateLength, way);
    }

    public static String generateCode(@NotNull String preString, @NotNull String mindString, String param3, @NotNull int generateLength, String way) {
        StringBuilder sb = new StringBuilder();
        generateLength = generateLength - preString.trim().length() - mindString.trim().length() - param3.trim().length();
        switch (way) {
            case "before":
                if (generateLength > 0) {
                    sb.append(SimpleStringUtils.getFixLenthString(generateLength));
                }
                sb.append(preString.trim()).append(mindString.trim()).append(param3.trim());
                return sb.toString().trim();
            case "mind":

                sb.append(preString.trim());
                if (generateLength > 0) {
                    sb.append(SimpleStringUtils.getFixLenthString(generateLength));
                }
                sb.append(mindString.trim()).append(param3.trim());
                return sb.toString().trim();
            case "after":
                sb.append(preString.trim()).append(mindString.trim());
                if (generateLength > 0) {
                    sb.append(SimpleStringUtils.getFixLenthString(generateLength));
                }
                sb.append(param3.trim());
                return sb.toString().trim();
            default:
                sb.append(preString.trim()).append(mindString.trim()).append(param3.trim());
                if (generateLength > 0) {
                    sb.append(SimpleStringUtils.getFixLenthString(generateLength));
                }
                return sb.toString().trim();

        }

    }

}
